<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>天气查询测试</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f5f5f5;
        }

        .container {
            background-color: white;
            border-radius: 10px;
            padding: 30px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }

        h1 {
            color: #333;
            text-align: center;
            margin-bottom: 30px;
        }

        .input-group {
            display: flex;
            margin-bottom: 20px;
        }

        #weather-input {
            flex: 1;
            padding: 12px;
            border: 2px solid #ddd;
            border-radius: 5px 0 0 5px;
            font-size: 16px;
            outline: none;
        }

        #weather-input:focus {
            border-color: #4CAF50;
        }

        #ask-weather {
            padding: 12px 20px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 0 5px 5px 0;
            cursor: pointer;
            font-size: 16px;
            transition: background-color 0.3s;
        }

        #ask-weather:hover {
            background-color: #45a049;
        }

        .examples {
            margin-top: 20px;
            padding: 15px;
            background-color: #e8f5e9;
            border-radius: 5px;
        }

        .examples h3 {
            margin-top: 0;
            color: #2e7d32;
        }

        .example-questions {
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
        }

        .example-btn {
            background-color: #c8e6c9;
            border: none;
            padding: 8px 12px;
            border-radius: 20px;
            cursor: pointer;
            font-size: 14px;
            transition: background-color 0.3s;
        }

        .example-btn:hover {
            background-color: #a5d6a7;
        }

        #result {
            margin-top: 20px;
            padding: 15px;
            border-radius: 5px;
            min-height: 50px;
        }

        .loading {
            background-color: #fff3e0;
            color: #ef6c00;
        }

        .success {
            background-color: #e8f5e9;
            color: #2e7d32;
        }

        .error {
            background-color: #ffebee;
            color: #c62828;
        }

        .hidden {
            display: none;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>🌤️ 天气查询助手</h1>

        <div class="input-group">
            <input type="text" id="weather-input" placeholder="请输入您想查询的天气问题，例如：今天北京天气怎么样？">
            <button id="ask-weather">查询天气</button>
        </div>

        <div class="examples">
            <h3>💡 示例问题</h3>
            <div class="example-questions">
                <button class="example-btn" data-question="北京现在的天气如何？">北京现在的天气如何？</button>
                <button class="example-btn" data-question="上海今天气温是多少度？">上海今天气温是多少度？</button>
                <button class="example-btn" data-question="广州明天会下雨吗？">广州明天会下雨吗？</button>
                <button class="example-btn" data-question="深圳当前天气状况">深圳当前天气状况</button>
                <button class="example-btn" data-question="杭州天气预报">杭州天气预报</button>
            </div>
        </div>

        <div id="result" class="hidden"></div>
    </div>

    <script>
        const weatherInput = document.getElementById('weather-input');
        const askWeatherBtn = document.getElementById('ask-weather');
        const resultDiv = document.getElementById('result');
        const exampleBtns = document.querySelectorAll('.example-btn');

        // 查询天气功能
        function askWeather() {
            const query = weatherInput.value.trim();

            if (!query) {
                showResult('请输入天气查询问题', 'error');
                return;
            }

            showResult('正在查询天气信息，请稍候...', 'loading');

            fetch(`/chat/weather?query=${encodeURIComponent(query)}`)
                .then(response => {
                    if (!response.ok) {
                        throw new Error('网络响应错误');
                    }
                    return response.text();
                })
                .then(data => {
                    showResult(`🌤️ ${data}`, 'success');
                })
                .catch(error => {
                    showResult(`查询失败: ${error.message}`, 'error');
                });
        }

        // 显示结果
        function showResult(message, type) {
            resultDiv.textContent = message;
            resultDiv.className = type;
            resultDiv.classList.remove('hidden');
        }

        // 事件监听
        askWeatherBtn.addEventListener('click', askWeather);

        weatherInput.addEventListener('keypress', (e) => {
            if (e.key === 'Enter') {
                askWeather();
            }
        });

        // 示例问题点击事件
        exampleBtns.forEach(btn => {
            btn.addEventListener('click', () => {
                const question = btn.getAttribute('data-question');
                weatherInput.value = question;
                askWeather();
            });
        });

        // 页面加载完成后的提示
        window.addEventListener('load', () => {
            showResult('请输入或选择一个天气查询问题开始测试', 'success');
        });
    </script>
</body>
</html>
